package com.seveneight.baijiesteward.ui.main.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.zxing.common.StringUtils;
import com.seveneight.baijiesteward.R;
import com.seveneight.baijiesteward.base.BaseActivity;
import com.seveneight.baijiesteward.bean.PayBackRecordBean;
import com.seveneight.baijiesteward.utils.ArithmeticUtils;
import com.seveneight.baijiesteward.utils.DateUtil;
import com.seveneight.baijiesteward.utils.StringFormat;

import butterknife.BindView;

/**
 * Created by user1 on 2018/3/29.
 */

public class OrderDetailActivity extends BaseActivity implements View.OnClickListener {

    @BindView(R.id.tv_title)
    TextView tv_title;
    @BindView(R.id.iv_back)
    ImageView iv_back;
    @BindView(R.id.tv_price)
    TextView tv_price;
    @BindView(R.id.tv_status)
    TextView tv_status;
    @BindView(R.id.tv_type)
    TextView tv_type;
    @BindView(R.id.tv_realprice)
    TextView tv_realprice;
    @BindView(R.id.tv_shouxu)
    TextView tv_shouxu;
    @BindView(R.id.tv_applytime)
    TextView tv_applytime;
    @BindView(R.id.tv_arrviedtime)
    TextView tv_arrviedtime;
    @BindView(R.id.tv_outCardNo)
    TextView tv_outCardNo;
    @BindView(R.id.tv_orderno)
    TextView tv_orderno;
    @BindView(R.id.tv_beizhi)
    TextView tv_beizhi;
    @BindView(R.id.layout_outtype)
    RelativeLayout layout_outtype;
    @BindView(R.id.layout_intype)
    RelativeLayout layout_intype;
    @BindView(R.id.tv_inCardNo)
    TextView tv_inCardNo;
    private PayBackRecordBean recordBean;


    @Override
    protected void initLayout() {
        setContentView(R.layout.activity_orderdetail);
    }

    @Override
    protected void initView() {
        tv_title.setText("订单详情");
    }

    @Override
    protected void initData() {
        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            recordBean = (PayBackRecordBean) bundle.getSerializable("recordBean");
        }
        tv_price.setText("¥" + StringFormat.formatNumber(recordBean.getAmount()));
        tv_realprice.setText("¥" + StringFormat.formatNumber(recordBean.getActualAmount()));
        double amount = Double.parseDouble(recordBean.getAmount());
        double actualAmount = Double.parseDouble(recordBean.getActualAmount());
        double sub = ArithmeticUtils.sub(actualAmount, amount);
        tv_shouxu.setText("¥" + StringFormat.formatNumber(Math.abs(sub) + ""));
        tv_applytime.setText(DateUtil.formatDate(recordBean.getCreatorTime()));
        tv_arrviedtime.setText(DateUtil.formatDate(recordBean.getSettleTime()));
        if (!TextUtils.isEmpty(recordBean.getOutBankName())) {
            layout_outtype.setVisibility(View.VISIBLE);
            String outType = (recordBean.getOutCardType() == 0 ? "借记卡" : "信用卡");
            tv_outCardNo.setText(recordBean.getOutBankName() + outType
                    + "(" + recordBean.getOutCardNo().substring(recordBean.getOutCardNo().length() - 4) + ")");
        }

        if (!TextUtils.isEmpty(recordBean.getInCardNo())) {
            String outType = (recordBean.getInCardType() == 0 ? "借记卡" : "信用卡");
            layout_intype.setVisibility(View.VISIBLE);
            tv_outCardNo.setText(recordBean.getInBankName()
                    + "(" + recordBean.getInCardNo().substring(recordBean.getInCardNo().length() - 4) + ")");
        }

        tv_orderno.setText(recordBean.getOrderNo());
        tv_beizhi.setText(recordBean.getDescription());
        switch (recordBean.getOrderStatus()) {
            case 0:
                tv_status.setText("未知");
                break;
            case 100:
                tv_status.setText("交易成功");
                break;
            case 101:
                tv_status.setText("交易中");
                break;
            case 102:
                tv_status.setText("交易失败");
                break;
        }
        switch (recordBean.getOrderType()) {
            case -1:
                tv_type.setText("未知");
                break;
            case 0:
                tv_type.setText("还款金充值");
                break;
            case 1:
                tv_type.setText("信用卡还款");
                break;
            case 2:
                tv_type.setText("提现金充值");
                break;
            case 3:
                tv_type.setText("借记卡提现");
                break;
            case 4:
                tv_type.setText("升级会员");
                break;
            case 5:
                tv_type.setText("信用卡绑定");
                break;
            case 6:

                break;
        }
    }

    @Override
    protected void setListener() {
        iv_back.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
        }
    }
}
